package main

import (
	"gitee.com/Frank098/devops-app-mgt/global"
	"gitee.com/Frank098/devops-app-mgt/router"
	"gitee.com/Frank098/devops-app-mgt/service"
	"gitee.com/Frank098/devops-app-mgt/utils/log"
	"github.com/gin-gonic/gin"
)

func init() {
	log.Info("应用初始化开始")
	if err := global.SetupSetting(); err != nil {
		log.Error("加载配置文件时发生错误 err: %v", err)
	}
	if err := global.SetupDBLink(); err != nil {
		log.Error("连接MySQL数据库时发生错误  err: %v", err)
	}
	if err := global.SetupRedisDB(); err != nil {
		log.Error("连接Redis数据库时发生错误  err: %v", err)
	}
	if err := service.K8s.KubernetesInit(global.KubeConfigSetting.Path); err != nil {
		log.Error("加载Kubernetes集群配置文件时发生错误  err: %v", err)
	}
	log.Info("应用初始化结束")
}

func main() {
	gin.SetMode(global.ServerSetting.RunMode)
	r := router.Register()
	go func() {
		if err := r.Run(global.ServerSetting.HttpPort); err != nil {
			log.Errorf("%+v\n", err)
		}
	}()

	done := make(chan int)
	<-done
}
